<?php
 /**
  *	PingCo PHP Framework : 模块基类
  *	Copyright (c) 2009 - 2010 Henter.
  *
  *	描述:开发基于PingCo开放平台开发第三方应用
  *	Author:Henter 511589173@qq.com
*/

class MOD
{

    function __construct()
    {	
		global $db;
		$this->db = &$db;
    }



	/**获取当前用户信息
	fields可以是uid,name,sex,birthday,height,weight,mychat,nickname,mymobile,interest,favoritemusic,favoritestar,favoritegame,favoritesoft,favoritecartoon,tinyurl,headurl,hometown_location,country,province,city,present_history,apples,goldapples,magicapples
	*/
	function userinfo($uids='',$fields = 'uid,name',$sid='')
	{
		global $api,$sid;
		$u = $api->users_getinfo($uids,$fields,$sid);
		return count($u['user']) > 1 ? $u['user'] : $u['user'][$fields];
	}
	
	
	/**
	通过UID获取会员名称
	*/
	function showusername($uid)
	{
		global $api;
		if(empty($uid)) return 'ERR';
		$u = $api->users_getinfo($uid,'name');
		return !empty($u['user']['name']) ? $u['user']['name'] : '';
	}
	
	
	/**
	通过ID获取场景名称
	*/
	function showchangjing($id)
	{
		global $db;
		if (empty($id)){return 'ERR';}
		$r =  $db->get_one("SELECT title FROM ".DB_PRE."changjing WHERE id = ".intval($id));
		//$r =array("title"=>321,"test"=>43);
		if(empty($r)) return '场景已删除';
		return count($r) > 1 ? $r : $r['title'];
	}
	
	
	/**
	通过ID获取角色名称
	*/
	function showjuese($id,$changjing='')
	{
		global $db;
		if (empty($id)){return 'ERR';}
		if($changjing){
			$r = $db->get_one("SELECT * FROM ".DB_PRE."changjing WHERE id =$changjing");
			switch($id){
				case 1 : $juesetmp = $r['juese1'];		break;
				case 2 : $juesetmp = $r['juese2'];		break;
				case 3 : $juesetmp = $r['juese3'];		break;
				case 4 : $juesetmp = $r['juese4'];		break;
			}
			return $juesetmp;
		}else{
			$r =  $db->get_one("SELECT title FROM ".DB_PRE."juese WHERE id = ".intval($id));
			//$r =array("title"=>321,"test"=>43);
			if(empty($r)) return '角色已删除';
			return count($r) > 1 ? $r : $r['title'];
		}

	}
	
	/**
	通过角色ID获取角色语气
	*/
	function showyuqi($id)
	{
		global $db;
		if (empty($id)){return 'ERR';}
		$r =  $db->get_one("SELECT yuqi FROM ".DB_PRE."juese WHERE id = ".intval($id));
		if(empty($r)) return '开心';
		//随机显示角色语气
		$yuqiarr = explode(" ", $r['yuqi']);
		$n = count($yuqiarr);
		$random=rand(0,$n-1);
		return $yuqiarr[$random];
	}
	
	
    /**
     * 重定向到指定的URL
     * @param   string  $url
     * @return  void
     */
    function redirect($url)
    {
        $url = strtr(trim($url), array("\r" => '', "\n" => ''));
        header("Location: $url\n", true);
        exit;
    }


    
    /**
     * destory this object
     *
     * @return  void
     */
    function destory()
    {}


};

?>
